import sys

from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import (
    QApplication, QMainWindow, QMenuBar, QMenu,QVBoxLayout, QWidget, QLabel
)
from PyQt6.QtCore import Qt


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle('PyQt6 Top and Bottom Menu Example')
        self.setGeometry(100, 100, 600, 400)

        # 创建并设置顶部菜单栏
        top_menu_bar = self.menuBar()
        file_menu = top_menu_bar.addMenu("File")

        new_action = QAction("New", self)
        new_action.triggered.connect(lambda: self.statusBar().showMessage("New selected"))
        file_menu.addAction(new_action)

        # 设置中心窗口部件
        central_widget = QWidget()
        self.setCentralWidget(central_widget)

        layout = QVBoxLayout()

        # 创建中间的内容
        label = QLabel("这是中心窗口的内容。")
        layout.addWidget(label)

        # 创建底部菜单栏
        bottom_menu_bar = QMenuBar()
        edit_menu = bottom_menu_bar.addMenu("Edit")

        cut_action = QAction("Cut", self)
        cut_action.triggered.connect(lambda: self.statusBar().showMessage("Cut selected"))
        edit_menu.addAction(cut_action)

        copy_action = QAction("Copy", self)
        copy_action.triggered.connect(lambda: self.statusBar().showMessage("Copy selected"))
        edit_menu.addAction(copy_action)

        # 将底部菜单栏添加到布局中
        layout.addWidget(bottom_menu_bar)

        central_widget.setLayout(layout)

        # 创建一个状态栏
        self.setStatusBar(self.statusBar())
        self.statusBar().showMessage("Ready")


app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
